﻿/*
 * Description: DFX点位监听
 */

#include "common_header.h"
#include <direct.h>
#include <thread>
#include "named_pipe_util.h"
#include "taskbar_monitor.h"

std::thread recvThread;

int main()
{
    std::string logName = "WinEvtMonitor";
    std::string logPath = "C:\\ProgramData\\WinEvtMonitor\\log";
    std::string logFile = logPath + "\\win_evt_monitor.log";
    if (GetFileAttributes(logPath.c_str()) == INVALID_FILE_ATTRIBUTES) {
        if (_mkdir(logPath.c_str()) != 0) {
            logFile = "C:\\Users\\Public\\win_evt_monitor.log";
        }
    }
    COMMON::Log::Init(logName, logFile);
    LOG_INFO("WinEventMonitor Start");
    if (!NamedPipeUtil::GetInstance().Init()) {
        LOG_ERR("NamedPipe init failed");
        return -1;
    }
    SetProcessShutdownParameters(0x100, 0);
    TaskBarMonitor::GetInstance().Init();
    recvThread = std::thread([]() {
        NamedPipeUtil::GetInstance().Recv();
    });
    if (recvThread.joinable()) {
        recvThread.join();
    }
    NamedPipeUtil::GetInstance().DeInit();
    TaskBarMonitor::GetInstance().DeInit();
    LOG_INFO("WinEventMonitor Exit");
    return 0;
}